import re
from math import ceil
import datetime

from httpGet import httpGetContent
from common import decimal

def getStockPosition(code, market):
    """
    处理股票盘口数据分析,分析所占的百分比率
    http://qt.gtimg.cn/q=s_pksz000858
    v_s_pksz000858="0.196~0.258~0.221~0.325";
    以 ~ 分割字符串中内容，下标从0开始，依次为：
    0: 买盘大单
    1: 买盘小单
    2: 卖盘大单
    3: 卖盘小单
    所占有的百分比百分比率
    """
    if code and market:
        url = "http://qt.gtimg.cn/q=s_pk%s%s" % (market, code)
        content = httpGetContent(url)
        if content:
            result_list = _get_content(content)
            if result_list:
                stock_dict = {}
                stock_dict["code"] = code
                stock_dict["market"] = market
                stock_dict["buy_big_percent"] = float(result_list[0])     # 买盘大单所占百分比
                stock_dict["buy_small_percent"] = float(result_list[1])   # 买盘小单所占百分比
                stock_dict["sell_big_percent"] = float(result_list[2])    # 卖盘大单所占比重
                stock_dict["sell_small_percent"] = float(result_list[3])  # 买盘小单所占比重
                stock_dict["date"] = datetime.date.today()
                return stock_dict

data = getStockPosition("000001","sh")               
print(data)